#include <bits/stdc++.h>
#define PII pair <int, int>
#define x first
#define y second
using namespace std;

const int N = 100010;

int n, res;
int a[N], b[N];

void dfs (int idx, int b, int r, int sum)
{
    if (idx == n + 1)
    {
        res = max (res, sum);
        return;
    }

    dfs (idx + 1, idx, r, sum + (a[idx] == a[b] ? a[b] : 0));
    dfs (idx + 1, b, idx, sum + (a[idx] == a[r] ? a[r] : 0));
}

int main ()
{
    freopen ("color.in", "r", stdin);
    freopen ("color.out", "w", stdout);

    int T;
    scanf ("%d", &T);
    while (T -- )
    {
        res = 0;
        scanf ("%d", &n);
        for (int i = 1; i <= n; i ++ )
            scanf ("%d", a + i);
        dfs (1, 0, 0, 0);
        printf ("%d\n", res);
    }
    return 0;
}
